{{define "admin/profile.html"}}
{{template "admin/page_start.html"}}
{{template "admin/navbar.html" .}}
{{template "admin/sidebar.html" .}}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Profile
        </h1>
        <ol class="breadcrumb">
            <li><a href="/admin/index"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Profile</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="col-md-6">
            <!-- Horizontal Form -->
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">个人信息</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form class="form-horizontal editprofile" method="post" action="/admin/profile">


                    <div class="box-body">
                        <div class="form-group">
                            <label for="inputnickName" class="col-sm-2 control-label">NickName</label>
                            <div class="col-sm-6">
                            {{if gt (len .user.NickName) 0}}
                                <input type="text" class="nickname form-control" name="nickName" id="inputnickName"
                                       value="{{.user.NickName}}"
                                       readonly placeholder="Nickname">
                            {{else}}
                                <input type="text" class="nickname form-control" name="nickName" id="inputnickName"
                                       value="{{.user.Email}}"
                                       readonly placeholder="Nickname">
                            {{end}}
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
                        {{if gt (len .user.Email) 0}}
                            <div class="col-sm-6">
                                <input type="email" class="email form-control" name="email" id="inputEmail3" value="{{.user.Email}}"
                                       readonly placeholder="Email">
                            </div>
                        {{else}}
                            <div class="col-sm-6">
                                <input type="email" class="form-control" name="email" id="inputEmail3" placeholder="Email">
                            </div>
                            <div class="col-sm-4">
                                <a href="#" class="btn btn-primary" onclick="bindEmail();">绑定</a>
                            </div>
                        {{end}}
                        </div>
                    {{/*<div class="form-group">*/}}
                    {{/*<label for="inputGithub" class="col-sm-2 control-label">Github</label>*/}}
                    {{/*{{if gt (len .user.GithubLoginId) 0}}*/}}
                    {{/*<div class="col-sm-6">*/}}
                    {{/*<input type="text" class="form-control" id="inputGithub" value="{{.user.GithubLoginId}}" readonly>*/}}
                    {{/*</div>*/}}

                    {{/*{{else}}*/}}
                    {{/*<div class="col-sm-4">*/}}
                    {{/*<a href="/auth/github" class="btn btn-primary">绑定</a>*/}}
                    {{/*</div>*/}}
                    {{/*{{end}}*/}}
                    {{/*</div>*/}}
                        <div class="form-group">
                            <label for="joinTime" class="col-sm-2 control-label">注册时间</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="joinTime"
                                       value="{{dateFormat .user.CreatedAt "2006-01-02 15:04:05"}}" readOnly>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button type="button" class="cancel btn btn-info pull-right">取消</button>
                        <button type="button" class="edit btn btn-info pull-right" style="margin-right: 20px;">编辑
                        </button>
                        <button type="submit" class="save btn btn-success pull-right" style="margin-right: 20px;">保存
                        </button>
                    </div>

                    <!-- /.box-footer -->
                </form>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
{{template "admin/page_end.html"}}
<script src="http://malsup.github.com/jquery.form.js"></script>
<script src="/static/libs/sweetalert/sweetalert.min.js" ></script>
<script type="text/javascript">
    $(function () {
        $('.edit').click(function () {
            $('.email').removeAttr("readonly");
            $('.nickname').removeAttr("readonly");
        })
        $('.cancel').click(function () {
            $('.email').attr("readonly", "readonly");
            $('.nickname').attr("readonly", "readonly");
        })
    });

    $(document).ready(function () {

        $('.editprofile').ajaxForm(function (data) {
            console.log(data);
            if (data.succeed) {
                swal({
                    title: "修改成功",
                    text: "马上就展现",
                    type: "success",
                    timer: 2000,
                    showConfirmButton: false
                });
                setTimeout(function () {
                    window.location.href = "/admin/profile"
                }, 2000);

            } else {
                swal({
                    title: "修改失败",
                    text: "请仔细检查",
                    type: "error",
                    timer: 2000,
                    showConfirmButton: false
                });
                setTimeout(function () {
                    window.location.href = "/admin/profile"
                }, 2000);

            }
        });
    });

    function bindEmail() {

    }

    function bindGithub() {

    }

    // function unbindGithub() {
    //     $.post("/admin/profile/github/unbind",{},function(result){
    //         if(result.succeed){
    //             window.location.reload(true)
    //         }
    //     },'json');
    // }
</script>

{{end}}